home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Files / Locations / TentativeFile.cp < prev    next >
Text File  |  2000-06-23  |  1KB  |  63 lines

  1. // TentativeFile.cp
  2.  
  3. #ifndef TentativeFile_h
  4. #include "TentativeFile.h"
  5. #endif
  6.  
  7. TentativeFile::TentativeFile( const FileLocation& theLocation,
  8.                                         FileType type,
  9.                                         ScriptID script )
  10.   : location( theLocation ),
  11.      committed( false )
  12.   {
  13.     CreateFile( location, type, script );
  14.   }
  15.  
  16. TentativeFile::TentativeFile( const FileLocation& theLocation,
  17.                                         FileType type,
  18.                                         FileSignature creator,
  19.                                         ScriptID script )
  20.   : location( theLocation ),
  21.      committed( false )
  22.   {
  23.     CreateFile( location, type, creator, script );
  24.   }
  25.  
  26. TentativeFile::~TentativeFile()
  27.   {
  28.     if ( committed )
  29.         return;
  30.  
  31.     try
  32.       {
  33.         DeleteFile( location );
  34.       }
  35.      catch (...)
  36.       {
  37.         Assert( 0 );
  38.       }
  39.   }
  40.  
  41. void TentativeFile::CommitReplacing( const FileLocation& toReplace )
  42.   {
  43.     Assert( !committed );
  44.     
  45.     SwapFiles( location, toReplace );
  46.     committed = true;
  47.     DeleteFile( toReplace );
  48.   }
  49.  
  50. FileLocation TentativeFile::GoodLocation( Volume volume,
  51.                                                         ConstPString nameHint )
  52.   {
  53.     FileLocation result( Directory::FindOrMake( kChewableItemsFolderType, volume ),
  54.                                 nameHint );
  55.     result.FindUnusedName();
  56.     return result;
  57.   }
  58.  
  59. FileLocation TentativeFile::GoodLocation( const FileLocation& hint )
  60.   {
  61.     return GoodLocation( hint.Volume(), hint.Name() );
  62.   }
  63.